{% extends '/layout.html' %}

{% block title %}上传图片{% endblock %}

{% block body %}
<h1>上传图片</h1>

<form method="POST">
    <input type="text" name="product_name" value="" id="product_name">
    <input type="file" name='avatar' id="avatar">
    <input type="button" id="submit_avatar" value="提交">
</form>

<img src="{{ url_for('api_product.get_avatar', game_num=4, name='作品')}}">

<script>
    $(document).ready(function(){
        $('#submit_avatar').click(function(e){
            alert('已发送请求');
            let form_data = new FormData();
            form_data.append("avatar", $('#avatar')[0].files[0]);
            form_data.append("product_name", $('#product_name').val())
            let url = '/api/users/avatar/{{ user_id }}';
            $.ajax({
                url:url,
                type: "POST",
                data: form_data,
                contentType: false,
                processData: false,
                success: function(data){
                    alert(data.message)
                }
            });
        });
    });
</script>

{% endblock %}